﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;
using WXYW.DAL;

namespace WXYW
{
    public partial class MaintainRecord : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindProductInfo();
            }
        }

        private void BindProductInfo()
        {
            ApplicationProductService service = new ApplicationProductService();
            ApplicationProduct product = service.GetApplicationProductByID(long.Parse(Request.QueryString[Constants.QUERYSTR_PRODUCT_ID]));

            rmaLabel.Text = product.ApplicationForm.ApplicationCode;
            typeLabel.Text = product.ProductType.ProductTypeName;
            serialLabel.Text = product.ProductSerialNumber;
            wxwcrqLabel.Text = product.RepairCompleteDateTime != null ? Convert.ToDateTime(product.RepairCompleteDateTime).ToString("yyyy-MM-dd hh:mm:ss") : "";
            if (product.Cost != null)
            {
                bjLabel.Text = product.Cost.ToString();
            }
            else
            {
                bjLabel.Text = "未报价";                
            }
        }

        protected void saveLinkButton_Click(object sender, EventArgs e)
        {
            ApplicationProductService service = new ApplicationProductService();
            ApplicationProduct product = service.GetSimpleApplicatonProductByID(long.Parse(Request.QueryString[Constants.QUERYSTR_PRODUCT_ID]));
            product.ProductAppearance = blxxTextBox.Text;
            product.ReasonToProblem = blyyDropDownList.Text;
            product.RepairAccessory = blljTextBox.Text;
            product.AccessoryPlace = ljwzTextBox.Text;
            if(thRadioButton.Checked)
            {
                product.ProductSerialNumber = thSerialNumberTextBox.Text;
                product.ChangeType = "替换";
            }
            if (ghRadioButton.Checked)
            {
                product.ChangeType = "更换";
            }
            product.Remark = bzTextBox.Text;
            product.Status = "维修完毕待发货";

            service.FinishMaintainProduct(product);
        }
    }
}
